package practise;

import javax.inject.Named;

import practise.APIResponse.Status;

import com.google.api.server.spi.config.Api;

@Api(name = "center")
public class CenterApi {
	
	public APIResponse getCenter(@Named("center") String centerName) {
		try {
			Center center = CenterRepository.get(centerName);
			
			if (null == center)
				return new APIResponse(Status.ERROR_RESOURCE_DOES_NOT_EXIST, null, 
						"Center [" + centerName + "] does not exist");
			
			return new APIResponse(Status.SUCCESS, center);
			
		} catch (Exception e) {
			return new APIResponse(e);
		}
	}
	
	public APIResponse addCenter(@Named("center") String centerName) {
		try {
			Center center = CenterRepository.add(centerName);
									
			return new APIResponse(Status.SUCCESS, center);
			
		} catch (Exception e) {
			return new APIResponse(e);
		}
	}
	
	public APIResponse deleteCenter(@Named("center") String centerName) {
		try {
			CenterRepository.delete(centerName);
									
			return new APIResponse(Status.SUCCESS, "center [" + centerName + "] deleted");
			
		} catch (Exception e) {
			return new APIResponse(e);
		}
	}
}
